package com.bdqn.petmalldemo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bdqn.petmalldemo.common.KetaiException;
import com.bdqn.petmalldemo.common.ResultCodeEnum;
import com.bdqn.petmalldemo.common.SystemConstants;
import com.bdqn.petmalldemo.entity.Order;
import com.bdqn.petmalldemo.entity.User;
import com.bdqn.petmalldemo.mapper.OrderDetailMapper;
import com.bdqn.petmalldemo.mapper.OrderMapper;
import com.bdqn.petmalldemo.mapper.UserMapper;
import com.bdqn.petmalldemo.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author:彭俊
 * @description:首页服务层实现类
 * @date:2020/3/41401
 */
@Service
public class IndexServiceImpl implements IndexService {
    @Autowired(required = false)
    private UserMapper userMapper;
    @Autowired(required = false)
    private OrderMapper orderMapper;
    @Autowired(required = false)
    private OrderDetailMapper orderDetailMapper;
    @Override
    public Map<String, Object> getUserInfo(String userId) {
        User userById = userMapper.selectById(userId).setPassword("");
        if (userById==null) {
           throw new KetaiException(ResultCodeEnum.USER_NOT_EXIST);
        }
        //获取当前登录用户的待收货订单
        QueryWrapper<Order> orderQueryWrapper = new QueryWrapper<>();
        orderQueryWrapper.eq("user_id",userId);
        List<Order> orderList = orderMapper.selectList(orderQueryWrapper);
        //待发货订单
        List<Order> sendOrderDetailList = orderMapper.selectOrderBySendStatus(SystemConstants.SEND_STATUS.UNSEND, userId);
        Map<String,Object> map=new HashMap<>(16);
        map.put("user",userById);
        map.put("receiveOrderList",orderList);
        map.put("sendOrderDetailList",sendOrderDetailList);
        return map;
    }
}
